﻿using D.UtilCore;

using D.UtilCore.Dtos;
using D.UtilCore.Filters;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using CozeDto.UserDtos;
using CozeDomain.IServices;
using CozeDto.AdminDtos;
using D.UtilFreesqlOrm;
using System.Security.Cryptography;
using D.Util.UtilSecurity;
using CozeDomain.Services;
using CozeDto.ProjectDtos;
using Microsoft.OpenApi.Writers;
using CozeDto.AiDtos;
using CozeDomain.Models;

namespace CozeWapApi
{
    /// <summary>
    /// 消息模块
    /// </summary>
    [Route("/api/[controller]/[action]")]
    public class CozeAiController : BaseApiController
    {
        private readonly ICozeAiService _aiService;
        public CozeAiController(ICozeAiService aiService)
        {
            _aiService = aiService;
        }

        /// <summary>
        /// 创建会话
        /// </summary>
        /// <param name="reqStartConversation"></param>
        /// <returns></returns>
        [HttpPost, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<RepCozeCreeateConversation>> Start([FromBody] ReqStartConversation reqStartConversation)
        {
            reqStartConversation.UserId = LoginId;
            return await _aiService.StartConversationAsync(reqStartConversation);
        }

        /// <summary>
        /// 创建消息
        /// </summary>
        /// <param name="reqMessage"></param>
        /// <returns></returns>
        [HttpPost, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<RepGetDialogueInfo>> Exec([FromBody] ReqMessage reqMessage)
        {
            reqMessage.UserId = LoginId;
            return await _aiService.ExecMessageAsync(reqMessage);
        }

        /// <summary>
        /// 获取消息历史
        /// </summary>
        /// <param name="reqMessageList"></param>
        /// <returns></returns>
        [HttpPost, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<RepQueryMessageList>> List([FromBody] ReqMessageList  reqMessageList)
        {
            return await _aiService.QueryMessageListAsync(reqMessageList);
        }
    }
}
